package com.molichuxing.services.business;

import java.math.BigDecimal;
import java.util.List;

import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.DocumentHelper;
import org.dom4j.Element;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.alibaba.fastjson.JSONObject;
import com.molichuxing.framework.result.ResponseResult;
import com.molichuxing.services.business.dto.request.create.MobileCreateDto;
import com.molichuxing.services.business.dto.response.CreditDto;
import com.molichuxing.services.business.service.MobileBizService;
import com.molichuxing.services.infrastructure.dto.request.create.GztThreeverifyNotifyLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.GztThreeverifyRequestLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyAntiSpoofingNotifyLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyAntiSpoofingRequestLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyCarFinanceNotifyLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyCarFinanceRequestLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyThreeverifyNotifyLogCreateDto;
import com.molichuxing.services.infrastructure.dto.request.create.PyThreeverifyRequestLogCreateDto;
import com.molichuxing.services.infrastructure.service.GztThreeverifyNotifyLogService;
import com.molichuxing.services.infrastructure.service.GztThreeverifyRequestLogService;
import com.molichuxing.services.infrastructure.service.PyAntiSpoofingNotifyLogService;
import com.molichuxing.services.infrastructure.service.PyAntiSpoofingRequestLogService;
import com.molichuxing.services.infrastructure.service.PyCarFinanceNotifyLogService;
import com.molichuxing.services.infrastructure.service.PyCarFinanceRequestLogService;
import com.molichuxing.services.infrastructure.service.PyThreeverifyNotifyLogService;
import com.molichuxing.services.infrastructure.service.PyThreeverifyRequestLogService;
import com.molichuxing.services.sdk.gzt.GztUtil;
import com.molichuxing.services.sdk.py.response.CisReport;
import com.molichuxing.services.sdk.py.response.PyResponseBean;
import com.molichuxing.services.sdk.py.response.car.CarFinanceScoreInfo;
import com.molichuxing.services.sdk.py.response.mobile.Item;
import com.molichuxing.services.sdk.py.response.mobile.MobileCheckInfo;
import com.molichuxing.services.sdk.py.response.person.anti.PersonAntiSpoofingInfo;
import com.molichuxing.services.util.PyParamsUtil;

/**
 * 
 * @author liyg
 * 三要素认证(手机号 + 姓名 + 身份证号)服务实现类
 * 2019-09-23
 *
 */
@Service("mobileBizService")
public class MobileBizServiceImpl implements MobileBizService{

	private static Logger logger = Logger.getLogger(MobileBizServiceImpl.class);
	
	@Value("${py.host}")
	private String host;
	@Value("${py.path}")
	private String path;
	@Value("${py.user.id}")
	private String userId;
	@Value("${py.password}")
	private String password;
	@Value("${verify.days}")
	private Integer verifyDays;
	@Value("${anti.spoofing.score}")
	private Integer antiSpoofingScore;
	@Value("${car.finance.score}")
	private Integer carFinanceScore;
	
	private final static String CHECKRESULT="一致";
	
	@Autowired
	private GztThreeverifyNotifyLogService gztThreeverifyNotifyLogService;
	
	@Autowired
	private GztThreeverifyRequestLogService gztThreeverifyRequestLogService;
	
	@Autowired
	private PyAntiSpoofingNotifyLogService pyAntiSpoofingNotifyLogService;
	
	@Autowired
	private PyAntiSpoofingRequestLogService pyAntiSpoofingRequestLogService;
	
	@Autowired
	private PyThreeverifyNotifyLogService pyThreeverifyNotifyLogService;
	
	@Autowired
	private PyThreeverifyRequestLogService pyThreeverifyRequestLogService;
	
	@Autowired
	private PyCarFinanceNotifyLogService pyCarFinanceNotifyLogService;
	
	@Autowired
	private PyCarFinanceRequestLogService pyCarFinanceRequestLogService;
	
	/**
	 * 三要素认证(手机号 + 姓名 + 身份证号)
	 * @param createDto
	 * @return
	 */
	@Override
	public ResponseResult<String> getMoblie(MobileCreateDto createDto) {
		String realName = createDto.getRealName();
		String idNumber = createDto.getIdNumber();
		String phone = createDto.getPhone();
		String result=null;
		//保存请求日志
		Integer requestId  = saveRequestMobliePy(realName,idNumber, phone);
		try {
			String params = PyParamsUtil.getCreditParam(realName, idNumber, phone);
			logger.info("鹏元三要素接口start");
			result = PyParamsUtil.requestApi(host, path, userId,password,params);
			logger.info("鹏元三要素接口出参:"+result);
		} catch (Exception e) {
			logger.error("鹏元三要素接口异常:",e);
			PyThreeverifyNotifyLogCreateDto logCreateDto=new PyThreeverifyNotifyLogCreateDto();
			logCreateDto.setRequestId(requestId);
			logCreateDto.setExternalStatus("500");
			logCreateDto.setExternalErrorMessage("调用鹏元三要素（个人反欺诈）接口异常");
			pyThreeverifyNotifyLogService.create(logCreateDto);
			return getGztData(realName, idNumber, phone);
		}
		
		ResponseResult<String> respone = getPyResult(phone,realName,idNumber,result,requestId);
		if(respone.getCode().equals(110)) {
			return getGztData(realName, idNumber, phone);
		}
		return respone;
	}

	/**
	 * 征信接口
	 * @param createDto
	 * @return
	 */
	@Override
	public ResponseResult<CreditDto> getCredit(MobileCreateDto createDto) {
		String realName = createDto.getRealName();
		String idNumber = createDto.getIdNumber();
		String phone = createDto.getPhone();
		String result=null;
		//保存请求日志
		Integer requestId  = saveRequestAntiPy(realName, idNumber, phone);
		CreditDto creditDto = new CreditDto();
		try {
			String params = PyParamsUtil.getCreditParam(realName, idNumber, phone);
			logger.info("鹏元个人反欺诈接口start");
			result = PyParamsUtil.requestApi(host, path, userId,password,params);
			logger.info("鹏元个人反欺诈接口出参:"+result);
		} catch (Exception e) {
			logger.error("鹏元个人反欺诈接接口异常:",e);
			PyAntiSpoofingNotifyLogCreateDto logCreateDto=new PyAntiSpoofingNotifyLogCreateDto();
			logCreateDto.setRequestId(requestId);
			logCreateDto.setExternalStatus("500");
			logCreateDto.setExternalErrorMessage("调用鹏元个人反欺诈接口异常");
			pyAntiSpoofingNotifyLogService.create(logCreateDto);
			return getCreditError(creditDto);
		}
		
		return getPyAntiResult(phone,realName,idNumber,result,requestId,creditDto);
	}
	
	
	
	/**
	 * 获取鹏元信用评分接口数据
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @param creditDto
	 * @return
	 */
	private ResponseResult<CreditDto> getPyCarFinanceData(String realName, String idNumber, String phone,CreditDto creditDto){
		String result=null;
		//保存请求日志
		Integer requestId = saveRequestCarFinancePy(realName, idNumber, phone);
		try {
			String params = PyParamsUtil.getFinanceParam(realName, idNumber, phone);
			logger.info("获取鹏元信用评分接口start");
			result = PyParamsUtil.requestApi(host, path, userId,password,params);
			logger.info("获取鹏元信用评分接口出参:"+result);
		} catch (Exception e) {
			logger.error("获取鹏元信用评分接口异常:",e);
			PyCarFinanceNotifyLogCreateDto logCreateDto=new PyCarFinanceNotifyLogCreateDto();
			logCreateDto.setRequestId(requestId);
			logCreateDto.setExternalStatus("500");
			logCreateDto.setExternalErrorMessage("调用鹏元信用评分接口异常");
			pyCarFinanceNotifyLogService.create(logCreateDto);
			return getCreditError(creditDto);
		}
		return  getPyCarFinanceResult(phone,realName,idNumber,result,requestId,creditDto);
	}
	
	/**
	 * 获取国政通接口数据
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @return
	 */
	private ResponseResult<String> getGztData(String realName, String idNumber, String phone){
		String result=null;
		//保存请求日志
		Integer requestId = saveRequestMoblieGzt(realName,idNumber,phone);
		try {
			GztUtil.getClient();
			logger.info("国政通三要素start");
			result = GztUtil.verifyThreefactor(idNumber, realName, phone);
			logger.info("国政通三要素出参:"+result);
		} catch (Exception e) {
			logger.error("国政通三要素接口异常:",e);
			GztThreeverifyNotifyLogCreateDto createDto=new  GztThreeverifyNotifyLogCreateDto();
			createDto.setRequestId(requestId);
			createDto.setExternalStatus("500");
			createDto.setErrorValue("调用国政通三要素接口异常");
			gztThreeverifyNotifyLogService.create(createDto);
			return getError();
		}
		return  getGztResult(phone,realName,idNumber,result,requestId);
	}
	
	/**
	 * 解析国政通数据  三要素
	 * @param phone
	 * @param realName
	 * @param idNumber
	 * @param result
	 * @param requestId
	 * @return
	 */
	private ResponseResult<String> getGztResult(String phone,String realName,String idNumber,String result,Integer requestId){
		 GztThreeverifyNotifyLogCreateDto createDto=new  GztThreeverifyNotifyLogCreateDto();
		    createDto.setExternalResponse(result);
		    createDto.setRequestId(requestId);
		    if(StringUtils.isBlank(result)) {
				createDto.setExternalStatus("500");
				createDto.setErrorValue("调用国政通驾驶证接口返回数据为空");
				gztThreeverifyNotifyLogService.create(createDto);
				return getGztError();
			}
		    Document doc=null;
			try {
				doc = DocumentHelper.parseText(result);
			} catch (DocumentException e) {
				createDto.setExternalStatus("500");
				createDto.setErrorValue("解析国政通三要素接口返回xml异常");
				return getError();
			}
		    Element root = doc.getRootElement();
	        Element mesElement=root.element("message");
	        Element statusElement=mesElement.element("status");
	        String status=statusElement.getStringValue();
	        createDto.setExternalStatus(status);
	        Element valueElement=mesElement.element("value");
	        String value=valueElement.getStringValue();
	        createDto.setErrorValue(value);
	        //0  处理成功 
	        if("0".equals(status)) {
	        	Element tnidBInfosElement = root.element("tnidBInfos");
	        	Element tnidBInfoElement = tnidBInfosElement.element("tnidBInfo");
	        	Element wybsElement = tnidBInfoElement.element("wybs");
	        	String wybs = wybsElement.getStringValue();
	        	createDto.setWybs(wybs);
	        	Element codeElement = tnidBInfoElement.element("code");
	        	String code = codeElement.getStringValue();
	        	createDto.setCode(code);
	        	Element messageElement= tnidBInfoElement.element("message");
	        	String message = messageElement.getStringValue();
	        	createDto.setMessage(message);
	        	//1:手机号、证件号、姓名均一致 
	        	if(StringUtils.isBlank(code) || !"1".equals(code)) {
	        		gztThreeverifyNotifyLogService.create(createDto);
	        		return getError();
	        		
	        	}
	        }else {
	        	gztThreeverifyNotifyLogService.create(createDto);
	        	return getError();
	        }
	        gztThreeverifyNotifyLogService.create(createDto);
	        return new ResponseResult<String>().success();
	}
	
	/**
	 * 解析鹏元数据  个人反欺诈
	 * @param phone
	 * @param realName
	 * @param idNumber
	 * @param result
	 * @param requestId
	 * @param creditDto
	 * @return
	 */
	private ResponseResult<CreditDto> getPyAntiResult(String phone,String realName,String idNumber,String result,Integer requestId,CreditDto creditDto){
		
		PyThreeverifyNotifyLogCreateDto createDto=new PyThreeverifyNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		if(StringUtils.isBlank(result)) {
			createDto.setExternalStatus("500");
			createDto.setExternalErrorMessage("调用鹏元个人反欺诈接口返回数据为空");
			pyThreeverifyNotifyLogService.create(createDto);
			return getCreditError(creditDto);
		}
		
		PyResponseBean pyResponseBean = JSONObject.parseObject(result, PyResponseBean.class);
		
		//保存鹏元反欺诈数据
		savePyAntiRespone(pyResponseBean,result,requestId);
		
		if (null != pyResponseBean && "1".equals(pyResponseBean.getStatus())) {
			List<CisReport> cisReports = pyResponseBean.getReturnValue().getCisReport();
			if(null == cisReports || cisReports.isEmpty()) {
				logger.error("《鹏元》  鹏元cisReports为空");
				return getCreditError(creditDto);
			}
			
			for (CisReport cisReport : cisReports) {

				if ("true".equals(cisReport.getHasSystemError()) || "true".equals(cisReport.getIsFrozen())) {
					logger.error("《鹏元》  鹏元系统错误||该客户是否被冻结");
					return getCreditError(creditDto);
				}
				
				PersonAntiSpoofingInfo person= cisReport.getPersonAntiSpoofingInfo();
				if(null == person) {
					logger.error("《鹏元》 mobileCheckInfo为空");
					return getCreditError(creditDto);
				}
				// 1：查得，2：未查得，3：其它原因未查得
				Integer treatResult =person.getTreatResult();
				if(null == treatResult) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getCreditError(creditDto);
				}else if (treatResult != 1) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getCreditError(creditDto);
				}
				
				//反欺诈评分>=75分直接拒绝
				BigDecimal riskScore = person.getRiskScore();
				creditDto.setRiskScore(riskScore);
				if(null == riskScore ||  riskScore.intValue() >= antiSpoofingScore) {
					return getCreditError(creditDto);
				}
			}
			//获取信用评分接口
			return getPyCarFinanceData(realName,idNumber,phone,creditDto);
		}
		return getCreditError(creditDto);
	}
	
	/**
	 * 获取错误信息
	 * @return
	 */
	private ResponseResult<String> getError(){
		return new ResponseResult<>(1, "抱歉，您未通过征信验证", null);
	}
	
	/**
	 * 获取错误信息
	 * @return
	 */
	private ResponseResult<CreditDto> getCreditError(CreditDto creditDto){
		return new ResponseResult<>(1, "抱歉，您未通过征信验证", creditDto);
	}
	
	/**
	 * 获取错误信息
	 * @return
	 */
	private ResponseResult<String> getGztError(){
		return new ResponseResult<>(110, "调用国政通接口", null);
	}
	/**
	 * 解析鹏元数据  金融评分
	 * @param phone
	 * @param realName
	 * @param idNumber
	 * @param result
	 * @param requestId
	 * @param creditDto
	 * @return
	 */
	private ResponseResult<CreditDto> getPyCarFinanceResult(String phone,String realName,String idNumber,String result,Integer requestId,CreditDto creditDto){
		
		PyCarFinanceNotifyLogCreateDto createDto=new PyCarFinanceNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		if(StringUtils.isBlank(result)) {
			createDto.setExternalStatus("500");
			createDto.setExternalErrorMessage("调用鹏元人脸识别接口返回数据为空");
			pyCarFinanceNotifyLogService.create(createDto);
			return getCreditError(creditDto);
		}
		
		PyResponseBean pyResponseBean = JSONObject.parseObject(result, PyResponseBean.class);
		
		//保存鹏元反欺诈数据
		savePyCarFinanceRespone(pyResponseBean,result,requestId);
		
		if (null != pyResponseBean && "1".equals(pyResponseBean.getStatus())) {
			List<CisReport> cisReports = pyResponseBean.getReturnValue().getCisReport();
			if(null == cisReports || cisReports.isEmpty()) {
				logger.error("《鹏元》  鹏元cisReports为空");
				return getCreditError(creditDto);
			}
			
			for (CisReport cisReport : cisReports) {
				
				if ("true".equals(cisReport.getHasSystemError()) || "true".equals(cisReport.getIsFrozen())) {
					logger.error("《鹏元》  鹏元系统错误||该客户是否被冻结");
					return getCreditError(creditDto);
				}
				
				CarFinanceScoreInfo carFinance= cisReport.getCarFinanceScoreInfo();
				if(null == carFinance) {
					logger.error("《鹏元》 mobileCheckInfo为空");
					return getCreditError(creditDto);
				}
				// 1：查得，2：未查得，3：其它原因未查得
				Integer treatResult =carFinance.getTreatResult();
				if(null == treatResult) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getCreditError(creditDto);
				}else if (treatResult != 1) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getCreditError(creditDto);
				}
				
				//信用评分校验（值做成可配置）：分数 0-360，不通过
				String score = carFinance.getScore();
				creditDto.setScore(score);
				if(StringUtils.isBlank(score) ||  Integer.valueOf(score) <= carFinanceScore) {
					return getCreditError(creditDto);
				}
			}
			return new ResponseResult<CreditDto>().success(creditDto);
		}
		
		return getCreditError(creditDto);
	}
	
	/**
	 * 解析鹏元数据  三要素
	 * @param phone
	 * @param realName
	 * @param idNumber
	 * @param result
	 * @param requestId
	 * @return
	 */
	private ResponseResult<String> getPyResult(String phone,String realName,String idNumber,String result,Integer requestId){
		
		PyThreeverifyNotifyLogCreateDto createDto=new PyThreeverifyNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		if(StringUtils.isBlank(result)) {
			createDto.setExternalStatus("500");
			createDto.setExternalErrorMessage("调用鹏元人脸识别接口返回数据为空");
			pyThreeverifyNotifyLogService.create(createDto);
			return getGztError();
		}
		
		PyResponseBean pyResponseBean = JSONObject.parseObject(result, PyResponseBean.class);
		
		//保存鹏元返回参数
		savePyRespone(pyResponseBean,result,requestId);
		
		if (null != pyResponseBean && "1".equals(pyResponseBean.getStatus())) {
			List<CisReport> cisReports = pyResponseBean.getReturnValue().getCisReport();
			if(null == cisReports || cisReports.isEmpty()) {
				logger.error("《鹏元》  鹏元cisReports为空");
				return getGztError();
			}
			
			for (CisReport cisReport : cisReports) {

				if ("true".equals(cisReport.getHasSystemError()) || "true".equals(cisReport.getIsFrozen())) {
					logger.error("《鹏元》  鹏元系统错误||该客户是否被冻结");
					return new ResponseResult<>(110, "调用国政通接口", null);
				}
				
				MobileCheckInfo mobileCheckInfo = cisReport.getMobileCheckInfo();
				if(null == mobileCheckInfo) {
					logger.error("《鹏元》 mobileCheckInfo为空");
					return getGztError();
				}
				// 1：查得，2：未查得，3：其它原因未查得
				Integer treatResult =mobileCheckInfo.getTreatResult();
				if(null == treatResult || treatResult ==3) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getGztError();
				}
				
				if (treatResult != 1 ) {
					logger.error("《鹏元》 子报告查询状态  未查得");
					return getError();
				}
				
				Item item = mobileCheckInfo.getItem();
				if (null == item.getNameCheckResult() || !CHECKRESULT.equals(item.getNameCheckResult())) {
					logger.error("《鹏元》 比对结果建议信息  建议拒绝 ");
					return getError();
				}
				if (null == item.getDocumentNoCheckResult() || !CHECKRESULT.equals(item.getDocumentNoCheckResult())) {
					logger.error("《鹏元》 比对结果建议信息  建议拒绝 ");
					return getError();
				}
				if (null == item.getPhoneCheckResult() || !CHECKRESULT.equals(item.getPhoneCheckResult())) {
					logger.error("《鹏元》 比对结果建议信息  建议拒绝 ");
					return getError();
				}
				
				return new ResponseResult<String>().success();
				
			}

		}
		return new ResponseResult<String>(110, "调用国政通接口", null);
	}
	
	/**
	 * 保存三要素信息
	 * @param py
	 * @param result
	 * @param requestId
	 */
	private void savePyRespone(PyResponseBean py,String result,Integer requestId) {
		PyThreeverifyNotifyLogCreateDto createDto=new PyThreeverifyNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		createDto.setExternalStatus(py.getStatus());
		createDto.setExternalErrorMessage(py.getErrorMessage());
		createDto.setExternalErrorCode(py.getErrorCode());
		createDto.setExternalResponse(result);
		if(null != py && "1".equals(py.getStatus())) {
			List<CisReport> cisReports = py.getReturnValue().getCisReport();
			
			MobileCheckInfo mobileCheckInfo =null;
			Item item=null;
			if(null != cisReports && cisReports.size()>0) {
				CisReport cisReport = cisReports.get(0);
				createDto.setIsFrozen(cisReport.getIsFrozen());
				createDto.setHasSystemError(cisReport.getHasSystemError());
				mobileCheckInfo = cisReport.getMobileCheckInfo();
			}
			
			if(null != mobileCheckInfo) {
				createDto.setTreatResult(mobileCheckInfo.getTreatResult());
				createDto.setErrorMessage(mobileCheckInfo.getErrorMessage());
				createDto.setTreatErrorCode(mobileCheckInfo.getTreatErrorCode());
				item= mobileCheckInfo.getItem();
			}
			
			if(null != item) {
				createDto.setNameCheckResult(item.getNameCheckResult());
				createDto.setDocumentNoCheckResult(item.getDocumentNoCheckResult());
				createDto.setPhoneCheckResult(item.getPhoneCheckResult());
				createDto.setOperatorName(item.getOperatorName());
				createDto.setAreainfo(item.getAreaInfo());
			}
		}
		pyThreeverifyNotifyLogService.create(createDto);
	}
	
	/**
	 * 保存鹏元金融评分返回的数据
	 * @param py
	 * @param result
	 * @param requestId
	 */
	private void savePyCarFinanceRespone(PyResponseBean py,String result, Integer requestId) {
		PyCarFinanceNotifyLogCreateDto createDto=new PyCarFinanceNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		createDto.setExternalStatus(py.getStatus());
		createDto.setExternalErrorMessage(py.getErrorMessage());
		createDto.setExternalErrorCode(py.getErrorCode());
		createDto.setExternalResponse(result);
		if(null != py && "1".equals(py.getStatus())) {
			List<CisReport> cisReports = py.getReturnValue().getCisReport();

			CarFinanceScoreInfo carFinanceScoreInfo =null;
			if(null != cisReports && cisReports.size()>0) {
				CisReport cisReport = cisReports.get(0);
				createDto.setIsFrozen(cisReport.getIsFrozen());
				createDto.setHasSystemError(cisReport.getHasSystemError());
				carFinanceScoreInfo = cisReport.getCarFinanceScoreInfo();
			}
			
			if(null != carFinanceScoreInfo) {
				BeanUtils.copyProperties(carFinanceScoreInfo, createDto);
			}
		}
		pyCarFinanceNotifyLogService.create(createDto);
	}
	
	/**
	 * 保存鹏元个人反欺诈返回的数据
	 * @param py
	 * @param result
	 * @param requestId
	 */
	private void savePyAntiRespone(PyResponseBean py,String result, Integer requestId) {
		PyAntiSpoofingNotifyLogCreateDto createDto=new PyAntiSpoofingNotifyLogCreateDto();
		createDto.setRequestId(requestId);
		createDto.setExternalStatus(py.getStatus());
		createDto.setExternalErrorMessage(py.getErrorMessage());
		createDto.setExternalErrorCode(py.getErrorCode());
		createDto.setExternalResponse(result);
		if(null != py && "1".equals(py.getStatus())) {
			List<CisReport> cisReports = py.getReturnValue().getCisReport();

			PersonAntiSpoofingInfo personAntiSpoofingInfo =null;
			if(null != cisReports && cisReports.size()>0) {
				CisReport cisReport = cisReports.get(0);
				createDto.setIsFrozen(cisReport.getIsFrozen());
				createDto.setHasSystemError(cisReport.getHasSystemError());
				personAntiSpoofingInfo = cisReport.getPersonAntiSpoofingInfo();
			}
			
			if(null != personAntiSpoofingInfo) {
				createDto.setTreatResult(personAntiSpoofingInfo.getTreatResult());
				createDto.setErrorMessage(personAntiSpoofingInfo.getErrorMessage());
				createDto.setTreatErrorCode(personAntiSpoofingInfo.getTreatErrorCode());
				createDto.setRiskScore(personAntiSpoofingInfo.getRiskScore());
				createDto.setSuggest(personAntiSpoofingInfo.getSuggest());
				createDto.setRiskLevel(personAntiSpoofingInfo.getRiskLevel());
				createDto.setHitTypes(personAntiSpoofingInfo.getHitTypes());
			}
		}
		pyAntiSpoofingNotifyLogService.create(createDto);
	}
	/**
	 * 保存请求国政通日志(三要素)
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @return
	 */
	private Integer saveRequestMoblieGzt(String realName, String idNumber, String phone){ 
		GztThreeverifyRequestLogCreateDto createDto=new GztThreeverifyRequestLogCreateDto();
		createDto.setIdNumber(idNumber);
		createDto.setPhoneNumber(phone);
		createDto.setFullName(realName);
		return gztThreeverifyRequestLogService.create(createDto);
	}
	
	/**
	 * 保存请求鹏元日志(三要素)
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @return
	 */
	private Integer saveRequestMobliePy(String realName, String idNumber, String phone){
		PyThreeverifyRequestLogCreateDto createDto=new PyThreeverifyRequestLogCreateDto();
		createDto.setIdNumber(idNumber);
		createDto.setPhoneNumber(phone);
		createDto.setFullName(realName);
		return pyThreeverifyRequestLogService.create(createDto);
	}
	
	/**
	 * 保存请求鹏元日志(鹏元个人反欺诈评分)
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @return
	 */
	private Integer saveRequestAntiPy(String realName, String idNumber, String phone){
		PyAntiSpoofingRequestLogCreateDto createDto=new PyAntiSpoofingRequestLogCreateDto();
		createDto.setIdNumber(idNumber);
		createDto.setPhoneNumber(phone);
		createDto.setFullName(realName);
		return pyAntiSpoofingRequestLogService.create(createDto);
	}
	
	/**
	 * 保存请求鹏元日志(鹏元汽车金融评分)
	 * @param realName
	 * @param idNumber
	 * @param phone
	 * @return
	 */
	private Integer saveRequestCarFinancePy(String realName, String idNumber, String phone){
		PyCarFinanceRequestLogCreateDto createDto=new PyCarFinanceRequestLogCreateDto();
		createDto.setIdNumber(idNumber);
		createDto.setPhoneNumber(phone);
		createDto.setFullName(realName);
		return pyCarFinanceRequestLogService.create(createDto);
	}
}
